﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ufida.u9.ait.openapi.utils;

namespace UFIDA.U9.YD.Cli.PlugBE.YD
{
    internal class OARest
    {
        //OA测试环境
        //private static String url1 = "http://192.168.1.33/api/FeiKong/v1/PaymentStatus";//付款确认
        //private static String url2 = "http://192.168.1.33/api/FeiKong/v1/UpdatePaymentStatus";//取消付款
        //OA正式环境
        private static String url1 = "http://192.168.1.28/api/FeiKong/v1/PaymentStatus";//付款确认
        private static String url2 = "http://192.168.1.28/api/FeiKong/v1/UpdatePaymentStatus";//取消付款

        /// <summary>
        /// 回写OA付款确认
        /// </summary>
        /// <param name="flowid">流程ID</param>
        /// <param name="docno">单号</param>
        /// <exception cref="Exception"></exception>
        public static void PayConfirm(string flowid,string docno)
        {
            string url = url1 + $"?requestid={flowid}&docno={docno}";
            string ret = HttpUtils.Post(url, "");
            OAResult oaret = JSONUtils.toObject<OAResult>(ret);
            if (oaret==null || oaret.Code != 200)
            {
                throw new Exception($"回写OA失败,{oaret?.Msg}! url:{url}");
            }
        }

        /// <summary>
        /// 回写OA付款取消
        /// </summary>
        /// <param name="flowid">流程ID</param>
        /// <param name="docno">单号</param>
        /// <exception cref="Exception"></exception>
        public static void PayUnConfirm(string flowid, string docno)
        {
            string url = url2 + $"?requestid={flowid}&docno={docno}";
            string ret = HttpUtils.Post(url, "");
            OAResult oaret = JSONUtils.toObject<OAResult>(ret);
            if (oaret == null || oaret.Code != 200)
            {
                throw new Exception($"回写OA失败,{oaret?.Msg}! url:{url}");
            }
        }
    }
}
